/*
 * @Author: yangni 920556271@qq.com
 * @Date: 2024-01-03 16:54:54
 * @LastEditors: yangni 920556271@qq.com
 * @LastEditTime: 2024-04-02 13:23:27
 * @FilePath: /yt-devops/lib/components/device/controll_switch.dart
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:yt_devops/model/device_obj/properties_model.dart';
import 'package:yt_devops/styles/styles.dart';

class DeviceSwitch extends StatefulWidget {
  final PropertiesModel model;

  /// 值
  final bool value;

  /// 是否可编辑
  final bool disable;

  /// 提示语
  final String? tip;

  final bool required;

  /// 切换回调
  final void Function(bool, bool)? onChanged;
  const DeviceSwitch(
      {required this.model,
      this.value = false,
      this.disable = false,
      this.tip,
      this.onChanged,
      this.required = false,
      super.key});

  @override
  State<DeviceSwitch> createState() => _DeviceSwitchState();
}

class _DeviceSwitchState extends State<DeviceSwitch> {
  @override
  Widget build(BuildContext context) {
    return Container(
        alignment: Alignment.center,
        child: BrnSwitchFormItem(
          title: widget.model.name!,
          value: widget.value,
          isEdit: !widget.disable,
          isRequire: false,
          error: widget.tip ?? '',
          themeData: BrnFormItemConfig(
            errorPadding: EdgeInsets.zero,
            titleTextStyle: BrnTextStyle(
              fontSize: 14.sp,
              color: Colour.mainTextColor,
            ),
          ),
          onChanged: (oldValue, newValue) {
            widget.onChanged?.call(oldValue, newValue);
          },
        ));
  }
}
